<#
AI 合规检查（原生 PowerShell）
用途：检查关键规则/文档是否存在，并扫描 TODO/FIXME 提示，作为基础合规巡检。
用法：
powershell -ExecutionPolicy Bypass -File scripts\windows\check-ai-compliance.ps1
#>
param()

$ScriptDir = Split-Path -Parent $PSCommandPath
$AIDDir = Split-Path -Parent $ScriptDir
$RootDir = Split-Path -Parent $AIDDir

$required = @(
  Join-Path $AIDDir "rules\ai_rules_and_prompts.md",
  Join-Path $AIDDir "rules\project_rules.md",
  Join-Path $AIDDir "docs\standard_prompts.md"
)

$missing = @()
foreach ($f in $required) { if (!(Test-Path $f)) { $missing += $f } }

function Count-Markers([string]$dir) {
  if (!(Test-Path $dir)) { return 0 }
  $files = Get-ChildItem -Path $dir -Recurse -File -Include *.md,*.txt
  $count = 0
  foreach ($f in $files) {
    $txt = Get-Content -Raw $f.FullName
    $count += ([regex]::Matches($txt, '(?mi)\bTODO\b|\bFIXME\b').Count)
  }
  return $count
}

$todoCount = (Count-Markers (Join-Path $AIDDir 'rules')) + (Count-Markers (Join-Path $AIDDir 'docs'))

Write-Host "[AI 合规] 必要文件缺失数：$($missing.Count)，标记计数：$todoCount"
if ($missing.Count -gt 0) {
  Write-Warning "缺失文件：`n - " + ($missing -join "`n - ")
}

if ($missing.Count -gt 0 -or $todoCount -gt 0) { exit 2 } else { Write-Host "AI 合规检查通过"; exit 0 }
